<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<script src="js/jquery-3.4.1.js"></script>
</head>
<body>
<form>
	用户名：<input type="text" id="userName" />
	学号：<input type="text" id="stuNo" />
	密码：<input type="password" id="password" />
	<input type="button" id="submit" value="提交" />
	<input type="button" id="newUser" value="注册"/>
</form>
<script>
	//注册绑定事件
	$("#newUser").click(function(){
		window.location.href="newUser.html"
	});
	//提交绑定事件
	$("#submit").click(function(){
		var stuNo=$("#stuNo").val();
		var userName=$("#userName").val();
		var upassword=$("#password").val();
		$.ajax({
			type:"post",
			url:"/studentDemo/UserLoginServlet",
			data: {"stuNo":stuNo,"userName":userName,"password":upassword},
			success:function(response){
				var data=JSON.parse(response);
				if(data.result=="ok"){
					alert(data.msg);
					window.location.href="listStudents.html";
				}else if(data.result=="error"){
					alert(data.msg);
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				alert("状态码:"+XMLHttpRequest.status+" |**| 状态:"+XMLHttpRequest.readyState+" |**| 错误信息:"+textStatus);
			},
			async:false
		});
	});
</script>
</body>
</html>